﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace website.template_faa.admin
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    public class getJCTHType : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            //点击datagrid的分页按钮，自动向后台发送2个参数,rows和page，代表每页记录数和页索引  
            int rows = int.Parse(context.Request["rows"].ToString());
            int page = int.Parse(context.Request["page"].ToString());
            System.Data.SqlClient.SqlDataReader reader = GetContent("tonghangJCLX", rows, page);
            int total = dbcaac.DBHelper.GetRecordCountByTable("tonghangJCLX");
            string text = dbcaac.JsonHelper.SqlDataReader2JsonForEasyUIDataGrid(total, reader);
            context.Response.Write(text);
            context.Response.End();
        }

        /// <summary>
        /// 访问数据库，获得分页记录
        /// </summary>
        /// <param name="pagesize">每页记录数</param>
        /// <param name="pageindex">页索引</param>
        /// <returns>DataSet</returns>
        private System.Data.SqlClient.SqlDataReader GetContent(string table, int pagesize, int pageindex)
        {
            System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[8];
            paras[0] = new System.Data.SqlClient.SqlParameter("@pageSize", pagesize);
            paras[1] = new System.Data.SqlClient.SqlParameter("@currentPage", pageindex);
            paras[2] = new System.Data.SqlClient.SqlParameter("@columns", "jclxId, jclxName");
            paras[3] = new System.Data.SqlClient.SqlParameter("@tableName", table);
            paras[4] = new System.Data.SqlClient.SqlParameter("@condition", "");
            paras[5] = new System.Data.SqlClient.SqlParameter("@ascColumn", "jclxId");
            paras[6] = new System.Data.SqlClient.SqlParameter("@bitOrderType", 0);
            paras[7] = new System.Data.SqlClient.SqlParameter("@pkColumn", "jclxId");

            return jsm.SqlHelper.SqlServerHelper.ExecuteReaderProc("dbcaac_GetPageOfRecords", paras);
        }  

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
